home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / envp2lis.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  1.2 KB  |  55 lines

  1. /*
  2. \funcref{envp2list}{VAR\_ envp2list (\params)}
  3.     {
  4.         {char} {**envp} {array of environment settings}
  5.     }
  6.     {list variable holding environment}
  7.     {newvar(), addtolist()}
  8.     {main()}
  9.     {envp2lis.c}
  10.     {
  11.  
  12.         This function converts the array of strings, which is passed to the
  13.         main function of {\em icm-exec} as {\em envp}, to a list. The list
  14.         consists of an even number of elements. The first element of each pair
  15.         is the name of the environment variable (e.g., ``path''); the second of
  16.         each pair is the setting of the variable.
  17.  
  18.         The returned {\em VAR\_} structure is pushed onto the {\em icmake}
  19.         stack by the {\em main()} function.
  20.  
  21.     }
  22. */
  23.  
  24. #include "icm-exec.h"
  25.  
  26. VAR_ envp2list (envp)
  27. char **envp;
  28. {
  29.     VAR_
  30.         ret;
  31.     char
  32.         buf [200];
  33.     register char
  34.         *cp;
  35.  
  36.     ret = newvar (e_list);
  37.     while (*envp)
  38.     {
  39.         strncpy (buf, *envp, 199);
  40.         if ( (cp = strrchr (buf, '=')) || (cp = strrchr (buf, ' ')) )
  41.         {
  42.             *cp = '\0';
  43.             cp++;
  44.             
  45.             ret = addtolist (ret, buf);
  46.             
  47.             if (! *cp)
  48.                 cp = " ";
  49.             ret = addtolist (ret, cp);
  50.         }
  51.         envp++;
  52.     }
  53.     return (ret);
  54. }
  55.